package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.ExpressTake;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import com.alibaba.fastjson2.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/12/13 10:35
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ExpressTakeVo extends BaseVO {
    /**
     * 用户id
     */
    private Long userId;

    private String avatar;

    private String nickname;
    /**
     * 业务单号
     */
    private String bizNo;
    /**
     * 收件地址
     */
    private AddressVo address;

    /**
     * 需要支付金额
     */
    private BigDecimal price;

    /**
     * 快递数量
     */
    private Integer amount;

    /**
     * 赏金
     */
    private BigDecimal bounty;

    /**
     * 性别限制,0不限制,1男,2女
     */
    private Integer sexLimit;

    /**
     * 期望送达时间,0不限,1上午,2下午,3晚上,4尽快,5其他时间请备注
     */
    private Integer deliveryTime;

    /**
     * 备注
     */
    private String remark;

    /**
     * 状态，0待接单,1已接单,2已取件,3已送达
     */
    private Integer status;

    /**
     * 是否支付
     */
    private Integer payStatus;

    /**
     * 支付时间
     */
    private String payTime;

    /**
     * 据当前多少时间
     */
    private String timeAgo;

    /**
     * 快递站点
     */
    private String expressStationStr;

    /**
     * 接单状态
     */
    private Integer applyStatus;

    /**
     * 快递详情
     */
    private List<ExpressTakeDetailVo> expressTakeDetails;


    public static ExpressTake convert(ExpressTakeVo param) {
        if (param == null) {
            return null;
        }
        ExpressTake expressTake = new ExpressTake();
        expressTake.setId(param.getId());
        expressTake.setUserId(param.getUserId());
        expressTake.setBizNo(param.getBizNo());
        expressTake.setAddress(JSON.toJSONString(AddressVo.convert(param.getAddress())));
        expressTake.setPrice(param.getPrice());
        expressTake.setAmount(param.getAmount());
        expressTake.setBounty(param.getBounty());
        expressTake.setSexLimit(param.getSexLimit());
        expressTake.setDeliveryTime(param.getDeliveryTime());
        expressTake.setRemark(param.getRemark());
        expressTake.setStatus(param.getStatus());
        expressTake.setPayStatus(param.getPayStatus());
        expressTake.setPayTime(DateUtil.parseString(param.getPayTime()));
        return expressTake;
    }

    public static ExpressTakeVo convert(ExpressTake param) {
        if (param == null) {
            return null;
        }
        ExpressTakeVo takeVo = new ExpressTakeVo();
        takeVo.setId(param.getId());
        takeVo.setUserId(param.getUserId());
        takeVo.setAvatar(param.getAvatar());
        takeVo.setNickname(param.getNickname());
        takeVo.setBizNo(param.getBizNo());
        takeVo.setAddress(JSON.parseObject(param.getAddress(), AddressVo.class));
        StringBuilder expressStationStr = new StringBuilder();
        List<ExpressTakeDetailVo> expressTakeDetailVos = param.getExpressTakeDetails().stream().map(item -> {
            expressStationStr.append(item.getExpressStation()).append("，");
            return ExpressTakeDetailVo.convert(item);
        }).collect(Collectors.toList());
        takeVo.setExpressStationStr(expressStationStr.substring(0, expressStationStr.length() - 1));
        takeVo.setExpressTakeDetails(expressTakeDetailVos);
        takeVo.setPrice(param.getPrice());
        takeVo.setAmount(param.getAmount());
        takeVo.setBounty(param.getBounty());
        takeVo.setSexLimit(param.getSexLimit());
        takeVo.setDeliveryTime(param.getDeliveryTime());
        takeVo.setRemark(param.getRemark());
        takeVo.setStatus(param.getStatus());
        takeVo.setPayStatus(param.getPayStatus());
        takeVo.setPayTime(DateUtil.format(param.getPayTime()));
        takeVo.setTimeAgo(DateUtil.getTimeAgo(param.getCreateTime()));
        takeVo.setCreateTime(DateUtil.format(param.getCreateTime()));
        takeVo.setUpdateTime(DateUtil.format(param.getUpdateTime()));
        return takeVo;
    }
}
